package ai.zixing.command01;

import java.util.ArrayList;

/**
 * 服务员-》 Invoker [调用者]
 */
public class Waiter {

    // 可以持有多个命令
    private ArrayList<Command> commands;

    public Waiter() {
        commands = new ArrayList<>();
    }

    public Waiter(ArrayList<Command> commands) {
        this.commands = commands;
    }

    public void setCommand(Command command) {
        this.commands.add(command);
    }

    // 发出指令
    public void orderUp() {
        System.out.println("服务员: 叮咚,有新的订单,请厨师开始制作......");
        for (Command cmd : commands) {
            if(cmd != null){
                cmd.execute();
            }
        }
    }
}
